package com.jie.controller;


import com.jie.annotation.OptLog;
import com.jie.entity.Video;
import com.jie.response.RespBean;
import com.jie.service.VideoService;
import com.jie.vo.ConditionVO;
import com.jie.vo.VideoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import static com.jie.constants.OptTypeConst.*;


@RestController
@RequestMapping("/video")
@Api(tags = "运动视频素材")
public class VideoController {

    @Autowired
    private VideoService videoService ;

    @OptLog(optType = SAVE)
    @ApiOperation(value = "添加运动视频素材")
    @PostMapping("/admin/saveVideo")
    public RespBean<?> saveVideo(@Valid @RequestBody VideoVO videoVO) {
        //后续这里会接入文件上传来定义视频地址路径 现在默认
        boolean video = videoService.createVideo(videoVO);
        return RespBean.success("添加运动视频素材是否成功",video);
    }
    //删除视频素材
    @OptLog(optType = REMOVE)
    @ApiOperation(value = "删除运动视频素材")
    @DeleteMapping("/admin/deleteVideo/{sportVideoId}")
    public RespBean<?> deleteVideo(@PathVariable("sportVideoId") Integer sportVideoId) {
        //后续这里会接入文件上传来定义视频地址路径 现在默认
        Integer id = videoService.deleteById(sportVideoId);
        return RespBean.success("删除成功",id);
    }
    @ApiOperation(value = "根据id查看运动视频素材")
    @GetMapping("/admin/getSportVideoById/{sportVideoId}")
    public RespBean<?> getSportVideoById(@PathVariable("sportVideoId") Integer sportVideoId) {
        //根据当前id获取当前视频素材
        Video video = videoService.getById(sportVideoId);
        return RespBean.success("video",video);
    }
    /**
     * 查看运动素材
     * @param conditionVO 条件
     */
    @ApiOperation(value = "查看运动素材")
    @GetMapping("/admin/operation/logs")
    public RespBean<?> listOperationLogs(ConditionVO conditionVO) {
        return RespBean.success("日志接口调用成功",videoService.listVideos(conditionVO));
    }


}
